<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="../include/laypublic.jsp"%>
<!DOCTYPE html>
<html>
<head>
<title>接待申请新建</title>
</head>
<style>
.fieldset {
	margin-top: 5px;
	margin-bottom: 0px
}

.layui-legend {
	background-color: #5fb878;
	font-size: 15px !important;
	width: 140px;
}

.layui-form-item {
	margin-bottom: 5px;
	clear: both;
	*zoom: 1;
}

.layui-form-label {
	width: 150px;
}
</style>
<body>
	<div class="layui-fluid">
		<div class="layui-card">
			<div class="layui-tab-item layui-show">
				<div style="padding-top: 15px;">&nbsp;</div>
				<form class="layui-form" id="addInfo_form">
					<fieldset class="layui-elem-field layui-field-title fieldset"
						id="baseInfo">
						<legend class="layui-btn layui-legend"
							style="text-align: left; cursor: default;">接待信息 ></legend>
						<div style="margin-top: 20px">
							<div class="layui-form-item">
								<div class="layui-inline">
									<label class="layui-form-label">申请公司</label>
									<div class="layui-input-inline">
										<input type="hidden" name="hrOrgid" value="${bindOrgId}">
										<input type="text" value="${bindOrgName}" style="border: 0px;"
											readonly="readonly" class="layui-input">
									</div>
								</div>
								<div class="layui-inline">
									<label class="layui-form-label">申请部门</label>
									<div class="layui-input-inline">
										<input type="hidden" name="hrDeptid" value="${bindDeptId}">
										<input type="text" value="${bindDeptName}"
											style="border: 0px;" readonly="readonly" class="layui-input">
									</div>
								</div>
								<div class="layui-inline">
									<label class="layui-form-label">申请人</label>
									<div class="layui-input-inline">
										<input type="hidden" name="hrStaffApplyid"
											value="${SESSION_KEY_USER_DETAIL.hrStaffId }"> <input
											type="text" name="staffname" value="${staffName }"
											readonly="readonly" style="border: 0px" autocomplete="off"
											class="layui-input">
									</div>
								</div>
							</div>

							<div class="layui-form-item">
								<div class="layui-inline">
									<label class="layui-form-label">接待日期</label>
									<div class="layui-input-inline">
										<input type="text" value="" lay-verify="required" id="receptionDate" name="serveDate"
											readonly="readonly" placeholder="请输入接待日期" class="layui-input">
									</div>
								</div>
							</div>

							<div class="layui-form-item">
								<div class="layui-inline">
									<label class="layui-form-label">申请事由</label>
									<div class="layui-input-inline">
										<textarea lay-verify="required" maxlength="500"
											placeholder="请输入申请事由" class="layui-textarea"
											style="width: 899px; height: 90px;" name="applyReason"></textarea>
									</div>
								</div>
							</div>
							<div class="layui-form-item">
								<div class="layui-inline">
									<label class="layui-form-label">来访单位</label>
									<div class="layui-input-inline">
										<textarea lay-verify="required" maxlength="500"
											placeholder="请输入来访单位" class="layui-textarea"
											style="width: 899px; height: 90px;" name="visitOrg"></textarea>
									</div>
								</div>
							</div>
							<div class="layui-form-item">
								<div class="layui-inline">
									<label class="layui-form-label">来访领导名单</label>
									<div class="layui-input-inline">
										<textarea lay-verify="required" maxlength="500"
											placeholder="请输入来访领导名单" class="layui-textarea"
											style="width: 899px; height: 90px;" name="visitLeaders"></textarea>
									</div>
								</div>
							</div>
							<div class="layui-form-item">
								<div class="layui-inline">
									<label class="layui-form-label">出席领导名单</label>
									<div class="layui-input-inline">
										<textarea lay-verify="required" maxlength="500"
											placeholder="请输入出席领导名单" class="layui-textarea"
											style="width: 899px; height: 90px;" name="ourLeaders"></textarea>
									</div>
								</div>
							</div>
							<div class="layui-form-item">
								<div class="layui-inline">
									<label class="layui-form-label">会议日期</label>
									<div class="layui-input-inline">
										<input type="text" value="" lay-verify="required"
											id="meetingDates" name="meetingDates" readonly="readonly"
											class="layui-input" placeholder="请输入会议日期">
									</div>
								</div>
								<div class="layui-inline">
									<label class="layui-form-label">会议室</label>
									<div class="layui-input-inline">
										<select name="meetingRoomId" lay-verify="required">
										<option value="">请选择</option>
										<c:if test="${not empty meetingRoomList}">
											<c:forEach items="${meetingRoomList}" var="meetingRoom">
												<option value="${meetingRoom.id}">${meetingRoom.roomName}</option>
											</c:forEach>
										</c:if>
										</select>
									</div>
								</div>
							</div>
							<div class="layui-form-item">
								<div class="layui-inline">
									<label class="layui-form-label">会议开始时间</label>
									<div class="layui-input-inline">
										<input type="text" value="" lay-verify="required"
											id="meetingStartTime" name="meetingStartTimes" readonly="readonly"
											class="layui-input" placeholder="请输入会议开始时间">
									</div>
								</div>
								<div class="layui-inline">
									<label class="layui-form-label">会议结束时间</label>
									<div class="layui-input-inline">
										<input type="text" value="" lay-verify="required"
											id="meetingEndTime" name="meetingEndTimes" readonly="readonly"
											class="layui-input" placeholder="请输入会议结束时间">
									</div>
								</div>
							</div>
							<div class="layui-form-item">
								<div class="layui-inline">
									<label class="layui-form-label">是否需要投影</label>
									<div class="layui-input-inline">
										<select name="projectorFlag" lay-verify="required">
											<option value="">请选择</option>
											<option value="1">是</option>
											<option value="0">否</option>
										</select>
									</div>
								</div>
								<div class="layui-inline">
									<label class="layui-form-label">是否需要茶水</label>
									<div class="layui-input-inline">
										<select name="teaFlag" lay-verify="required">
											<option value="">请选择</option>
											<option value="1">是</option>
											<option value="0">否</option>
										</select>
									</div>
								</div>
								<div class="layui-inline">
									<label class="layui-form-label">是否需要鲜花</label>
									<div class="layui-input-inline">
										<select name="flowerFlag" lay-verify="required">
											<option value="">请选择</option>
											<option value="1">是</option>
											<option value="0">否</option>
										</select>
									</div>
								</div>
							</div>
							
							<div class="layui-form-item">
								<div class="layui-inline">
									<label class="layui-form-label">是否需要水果</label>
									<div class="layui-input-inline">
										<select name="fruitsFlag" lay-verify="required">
											<option value="">请选择</option>
											<option value="1">是</option>
											<option value="0">否</option>
										</select>
									</div>
								</div>
								<div class="layui-inline">
									<label class="layui-form-label">对方联系人姓名</label>
									<div class="layui-input-inline">
										<input type="text" value="" lay-verify="required" autocomplete="off"
											name="linkName" placeholder="请输入对方联系人姓名" class="layui-input">
									</div>
								</div>
								<div class="layui-inline">
									<label class="layui-form-label">对方联系人电话</label>
									<div class="layui-input-inline">
										<input type="text" value="" lay-verify="required|telNumber" maxlength="11" autocomplete="off" onblur="checkTel(this)"
											name="linkPhone" placeholder="请输入对方联系人电话" class="layui-input">
									</div>
								</div>
							</div>
							<div class="layui-form-item" >
								<div class="layui-inline" >
									<label class="layui-form-label">费用申请</label>
									<div class="layui-input-inline">
										<textarea lay-verify="required" maxlength="100"
											placeholder="请输入费用申请" class="layui-textarea"
											style="width: 899px; height: 90px;" name="costApply"></textarea>
									</div>
								</div>
							</div>
						
						</div>
					</fieldset>

					<fieldset class="layui-elem-field layui-field-title fieldset" >
						<legend class="layui-btn layui-legend" style="text-align: left; cursor: default;" >附件信息 ></legend>
						<div style="margin-top: 20px;">
							<div class="layui-form-item">
								<label class="layui-form-label" style="width: 350px;">支持pdf、excel、word、图片资料，可上传多个</label>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label" >接待方案（选填）</label>
								<div class="layui-input-block">
									<div class="layui-upload">
										<button type="button" class="layui-btn" id="1-upload-more">上传</button>
										<div class="layui-upload-list" id="1-upload-more-list">
										</div>
									</div>
								</div>
							</div>
							<div class="layui-form-item" >
								<label class="layui-form-label" >其他附件（选填）</label>
								<div class="layui-input-block" >
									<div class="layui-upload"  >
										<button type="button" class="layui-btn" id="2-upload-more" >上传</button>
										<div class="layui-upload-list" id="2-upload-more-list">
										</div>
									</div>
								</div>
							</div>
						</div>
					</fieldset>

					<div class="layui-form-item"
						style="position: fixed ! important; right: 30px; bottom: 45%; z-index: 10000;">
						<div class="layui-input-block">
							<button
								class="layui-btn layui-bg-blue layui-btn-normal layui-btn-lg  layui-btn-radius"
								type="button" lay-submit lay-filter="addInfo_form_submit"
								id="addInfo_form_submit">
								<i class="layui-icon layui-icon-ok layuiadmin-button-btn"></i>确认提交
							</button>
						</div>
					</div>
				</form>
			</div>
		</div>
	</div>
	<script>


		//删除文件
		function del(index) {
			layui.$("#fileAtt_" + index).remove();
			layui.$("#upload_img_" + index).remove();
		}

		//根据url查看文件
		function showImg(url) {
			var openWin = window.open(url,'','left=410,height=768, width=1024, top=200,  toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no');
		}
		
		//静态资源路径前缀
		var staticPath = '${fileHttpPre}';
		var stateJSON = <infopub:dicJson groupNo="A00010028" />;

		layui.config({
					base : '${ctx}/resources/layuiadmin/' //静态资源所在路径
				}).extend({
					index : 'lib/index' //主入口模块
				}).use(
						[ 'index', 'set', 'upload', 'element', 'laydate' ],
						function() {
							var $ = layui.$, form = layui.form, element = layui.element, laydate = layui.laydate, upload = layui.upload;
							form.verify({
										CHS : [ /^[\u0391-\uFFE5]+$/, '只能输入汉字' ],
										intNumber : [ /^[1-9]\d*$/, '请输入正确的数字' ],
										floatNumber : [
												/^([-]?)([0-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/,
												'请输入正确的数字' ],
										//电话号码
										telNumber:[/^((0\d{2,3}-\d{7,8})|([1][3,4,5,7,8,9][0-9]{9}))$/,'请输入正确的号码'], 
										floatAmount : [
												/^([1-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/,
												'请输入正确的数字' ]
									});
							
							var laydate = layui.laydate;
							laydate.render({
								elem : '#receptionDate',trigger: 'click' 
							});
							
							laydate.render({
							    elem: '#meetingStartTime'
							    ,type: 'time',trigger: 'click' 
							    ,btns: ['clear', 'confirm']
							});
							
							laydate.render({
							    elem: '#meetingEndTime'
							    ,type: 'time',trigger: 'click' 
							    ,btns: ['clear', 'confirm']
							});
							
							laydate.render({
						     	elem: '#meetingDates',trigger: 'click' 
					 		});
							
							$('.decimal').on('keyup', function() {
										var val = this.value.replace(
												/^(\-)*(\d+)\.(\d\d).*$/,
												'$1$2.$3');
										var val2 = val.replace(/[^0-9.]/g, "");
										this.value = val2;
									});
							
							
							var uploadRender = function(id) {
								upload.render({
									elem : '#' + id + '-upload-more',
									url : basePath+'/serveRecord/uploadAtt/',
									data : {
										types : id
									},
									multiple : true,
									accept : 'file',
									acceptMime : 'application/zip,application/x-rar-compressed,image/jpeg,image/png,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.ms-powerpoint,application/vnd.openxmlformats-officedocument.presentationml.presentation,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/pdf',
									before : function(obj) {
										layer.load();
									},
									done : function(res) {
										if (res.code > 0) {
											layer.closeAll('loading');
											return layer.msg(res.msg, {
												icon : 7
											});
										}
										if (res.entity != null&& res.entity.length > 0) {
											for ( var i in res.entity) {
												var preProject = res.entity[i];
												var arr = preProject
														.split("|");
												var imgSrc = "";
												var suffix = arr[1].substring(arr[1].lastIndexOf(".") + 1,arr[1].length);
												if (suffix == 'jpg'|| suffix == 'png') {
													imgSrc = "${fileHttpPre}/"+arr[3];
												} else {
													imgSrc = "${ctx}/resources/images/"+suffix+".jpg";
												}
												$('#'+id+'-upload-more-list').append('<div class="layui-upload-img-div" id="upload_img_'+arr[2]+'"><img src="'+imgSrc+'" title="'+ arr[1] +'" class="layui-upload-img"><div class="mask"><a href="javascript:void(0)" onclick="showImg(\''+"${fileHttpPre}"+arr[3]+'\');">查看</a><a href="javascript:void(0)" onclick="del(\''+arr[2]+'\')";>删除</a></div><p>'+arr[1]+ '</p><input type="hidden" value="'+preProject+'" id="fileAtt_'+arr[2]+'" name="fileAtts'+id+'" ></input></div>');
											}
										}
									},
									allDone : function(obj) {
										layer.closeAll('loading');
									},
									error : function() {
										layer.closeAll('loading');
										layer.msg("上传失败，请稍后再试~", {
											icon : 7
										});
									}
								});
								}
								for (var i = 1; i < 3; i++) {
									uploadRender(i);
								}
							
								form.on('submit(addInfo_form_submit)', function(data) {
									$("#addInfo_form_submit").removeAttr("lay-submit").removeClass("layui-bg-blue").addClass("layui-btn-disabled");
									//提交 Ajax 成功后，静态更新表格中的数据
						               $.ajax({
						                   type : 'post',
						         		   url : basePath + '/serveRecord/save',
						                   data: $('#addInfo_form').serialize(),
						         		   success:function(result){
						         				if(result.success){
						         					layer.closeAll('loading'); //关闭loading
						         					layer.msg('提交单据成功~',{icon: 1});
						         					//两秒后关闭当前页面
						         					setTimeout(function(){
						         						/**
						         						 * 查找父菜单，并刷新
						         						 */
						         						var topDoc = $(window.top.document);
						         						var path = basePath + '/serveRecord/list';
						         						// 获取页面名称
						         						var name = topDoc.find(".layui-nav-item [lay-href^='" + path + "']").text();
						         						if(name == '' || name == null){
						         							name = '接待申请';
						         						}
						         						window.parent.layui.index.openTabsPage(path, name);
						         						var iframe = window.parent.layui.admin.tabsBody(window.parent.layui.admin.tabsPage.index).find(".layadmin-iframe");
						         						iframe[0].contentWindow.location.reload(true);
						         						
						         						/**
						         						 * 关闭当前页
						         						 */
						         						var currPath = basePath + '/serveRecord/add';
						         						var layid = topDoc.find("li[lay-id^='" + currPath + "']").attr('lay-id');
						         						window.parent.layui.element.tabDelete('layadmin-layout-tabs', layid);//关闭当前页
						         				        }, 2000);
						         				}else{
						         					layer.closeAll('loading'); //关闭loading
						           					$("#addInfo_form_submit").removeClass("layui-btn-disabled").addClass("layui-bg-blue").attr("lay-submit","");
						         					layer.msg(result.msg,{icon: 7});
						         			  	}
						         			}
						              });
								});
							
						});
		//'请输入正确电话号码！'
		function checkTel(str) {
			var $ = layui.$, form = layui.form
			if (str.value == '' || str.value == null) {
				return;
			}
			var rgx1 =/^[1][3,4,5,7,8,9][0-9]{9}$/;//手机号码校验
			var rgx2 =/^0\d{2,3}-?\d{7,8}$/;//固定电话校验
			var boolrgx1 = rgx1.test(str.value);
			var boolrgx2 = rgx2.test(str.value);
			if (boolrgx1==true||boolrgx2==true) {
				return true;
			} else {
				str.value ='';
				layer.msg('请输入正确电话号码！');
				return false;
			}
		}
	</script>
</body>
</html>

